/* GUI CONVERTED from rwroru01.p (converter v1.75) Thu Jun 28 21:18:59 2001 */
/* rwroru01.p - ROUTING OPERATION COST CALCULATION                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.6.1.5 $                                                         */
/*V8:ConvertMode=Maintenance                                                */
/* REVISION: 7.3        LAST MODIFIED: 02/16/93     BY: emb *G701*          */
/* REVISION: 7.3        LAST MODIFIED: 05/12/93     BY: pma *GA86*(rev only)*/
/* REVISION: 7.2        LAST MODIFIED: 12/29/93     BY: ais *FL07           */
/* REVISION: 7.5        LAST MODIFIED: 10/20/94     BY: mwd *J034*          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 07/23/98   BY: *J2TK* Thomas Fernandes */
/* REVISION: 9.0      LAST MODIFIED: 02/14/00   BY: *J3NY* Jyoti Thatte     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* Old ECO marker removed, but no ECO header exists *FL07*                  */
/* Revision: 1.6.1.4     BY: Hualin Zhong   DATE: 05/08/01 ECO: *N0YC*      */
/* $Revision: 1.6.1.5 $    BY: Rajesh Thomas   DATE: 06/27/01 ECO: *M1CD*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */
{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rwroru01_p_1 "Update Operation Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE rwroru01_p_2 "Update Alternate Routings"
/* MaxLen: Comment: */

&SCOPED-DEFINE rwroru01_p_3 "As of Date"
/* MaxLen: Comment: */

&SCOPED-DEFINE rwroru01_p_4 "Include Yield in Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE rwroru01_p_6 "Update Items At This Site Only"
/* MaxLen:39  Comment: Update Items existing at the specified site */

/* ********** End Translatable Strings Definitions ********* */

define variable eff_date as date
   label {&rwroru01_p_3} initial today.
define variable part1 like pt_part.
define variable part2 like pt_part.
define variable part_type like pt_part_type.
define variable inc_yield like mfc_logical initial true
   label {&rwroru01_p_4}.
define variable update-alts like mfc_logical initial true
   label {&rwroru01_p_2}.
define variable update-op like mfc_logical initial true
   label {&rwroru01_p_1}.
define variable part_yield as decimal no-undo.
define variable ord_qty like pt_ord_qty no-undo.
define variable yn like mfc_logical no-undo.
define variable site like si_site no-undo.
define variable csset like sct_sim no-undo.
define variable method as character format "x(15)" no-undo.
define variable routing like ro_routing no-undo.
define variable cum_yield as decimal no-undo.
define variable bom_code like pt_bom_code no-undo.
define variable gl_set like icc_gl_set no-undo.
define variable mtl_this_op as decimal no-undo.
define variable lbr_this_op as decimal no-undo.
define variable bdn_this_op as decimal no-undo.
define variable sub_this_op as decimal no-undo.
define variable ovh_this_op as decimal no-undo.
define variable mtl_prev_op as decimal no-undo.
define variable lbr_prev_op as decimal no-undo.
define variable bdn_prev_op as decimal no-undo.
define variable sub_prev_op as decimal no-undo.
define variable ovh_prev_op as decimal no-undo.
define variable mtl_in as decimal no-undo.
define variable lbr_in as decimal no-undo.
define variable bdn_in as decimal no-undo.
define variable sub_in as decimal no-undo.
define variable ovh_in as decimal no-undo.
define variable existing_items like mfc_logical initial yes
   label {&rwroru01_p_6} no-undo.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
site           colon 25 si_desc no-label
   csset          colon 25 cs_desc no-label
   method         no-label skip(1)
   part1          colon 25
   part2          label {t001.i} skip (1)
   part_type      colon 32
   eff_date       colon 32
   inc_yield      colon 32
   update-alts    colon 32
   existing_items colon 32

 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

site = global_site.

find first icc_ctrl no-lock no-error.
if not available icc_ctrl then do:

   {pxmsg.i &MSGNUM=533
            &ERRORLEVEL=4
            &MSGARG1=getTermLabel(""INVENTORY"",12)}

   repeat:
      if batchrun = no then pause.
      leave.
   end.
   undo, leave.
end.
assign
   gl_set = icc_gl_set
   csset = gl_set.

find si_mstr no-lock where si_site = site no-error.
if available si_mstr then do:
   display site si_desc with frame a.
   if si_gl_set > "" then csset = si_gl_set.
end.

display csset with frame a.
find cs_mstr where cs_set = csset no-lock no-error.
method = "".
if available cs_mstr then do:
   method = "[ " + cs_method + " / " + cs_type + " ]".
   display cs_desc method with frame a.
end.
else display "" @ cs_desc method with frame a.

display
   site
   part1
   part2
   part_type
   eff_date
   inc_yield
   update-alts
   existing_items
with frame a.

repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   if part2 = hi_char then part2 = "".

   seta1:
   do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      set site with frame a
      editing:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i si_mstr site si_site site si_site si_site}

         if recno <> ? then do:
            site = si_site.
            display site si_desc with frame a.

            csset = gl_set.
            if si_gl_set > "" then csset = si_gl_set.
            display csset with frame a.
            find cs_mstr where cs_set = csset no-lock no-error.
            method = "".
            if available cs_mstr then do:
               method = "[ " + cs_method + " / " + cs_type + " ]".
               display cs_desc method with frame a.
            end.
            else display "" @ cs_desc method with frame a.

            recno = ?.
         end.
      end. /* EDITING */

      find si_mstr where si_site = site no-lock no-error.
      if not available si_mstr then do:
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /*site does not exist*/
         next-prompt site with frame a.
         undo, retry.
      end.

      display si_desc with frame a.

      if si_db <> global_db then do:
         {pxmsg.i &MSGNUM=5421 &ERRORLEVEL=3}
         /*site is not assigned to this database*/
         next-prompt site with frame a.
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /*USER DOES NOT HAVE ACCESS TO THIS SITE */
         next-prompt site with frame a.
         undo seta1, retry seta1.
      end.

      csset = gl_set.
      if si_gl_set > "" then csset = si_gl_set.
      display csset with frame a.
      find cs_mstr where cs_set = csset no-lock no-error.
      method = "".
      if available cs_mstr then do:
         method = "[ " + cs_method + " / " + cs_type + " ]".
         display cs_desc method with frame a.
      end.
      else display "" @ cs_desc method with frame a.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   seta2:
   do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      set csset with frame a
      editing:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i cs_mstr csset cs_set csset cs_set cs_set}

         if recno <> ? then do:
            csset = cs_set.
            display csset with frame a.
            find cs_mstr where cs_set = csset no-lock no-error.
            method = "".
            if available cs_mstr then do:
               method = "[ " + cs_method + " / " + cs_type + " ]".
               display cs_desc method with frame a.
            end.
            recno = ?.
         end.
      end.

      if csset = "" then do:
         {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}  /*Blank not allowed*/
         next-prompt csset.
         undo, retry.
      end.

      find cs_mstr where cs_set = csset no-lock no-error.
      if not available cs_mstr then do:
         {pxmsg.i &MSGNUM=5407 &ERRORLEVEL=3} /*Cost set does not exist*/
         next-prompt csset.
         undo, retry.
      end.

      method = "[ " + cs_method + " / " + cs_type + " ]".
      display cs_desc method with frame a.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   ststatus = stline[3].
   status input ststatus.

   update
      part1
      part2
      part_type
      eff_date
      inc_yield
      update-alts
      existing_items
   with frame a.

   if part2 = "" then part2 = hi_char.

   if eff_date = ?
   then do:
      eff_date =  today.
      display eff_date with frame a.
   end. /* IF eff_date ... */

   yn = yes.
   /*Begin routing roll-up ? */
   {pxmsg.i &MSGNUM=207 &ERRORLEVEL=1 &CONFIRM=yn}
   if not yn then undo, retry.

   for each pt_mstr no-lock
         where pt_part  >= part1 and pt_part  <= part2
         and  (part_type = ""    or  part_type = pt_part_type):
/*GUI*/ if global-beam-me-up then undo, leave.


      /* IF THE EXISTING_ITEMS FLAG IS SET TO YES AND IF THERE ARE   */
      /* NO INVENTORY MASTER RECORDS FOR THAT ITEM AT THAT SPECIFIED */
      /* SITE THEN THE COST WON'T BE CALCULATED FOR THAT ITEM TO     */
      /* AVOID CREATION OF UNWANTED RECORDS                          */

      if existing_items then do:
         if not can-find (in_mstr where in_part = pt_part
            and   in_site = site) then next.
      end. /* IF EXISTING_ITEMS THEN */

      assign
         routing = pt_part.
         bom_code = pt_part.
         ord_qty = 1.

      find ptp_det no-lock where ptp_part = pt_part
         and ptp_site = site no-error.
      if available ptp_det then do:
         if ptp_routing <> "" then routing = ptp_routing.
         if ptp_bom_code <> "" then bom_code = ptp_bom_code.
         if ptp_ord_qty <> 0 then ord_qty = ptp_ord_qty.
      end.
      else do:
         if pt_routing > "" then routing = pt_routing.
         if pt_bom_code > "" then bom_code = pt_bom_code.
         if pt_ord_qty <> 0 then ord_qty = pt_ord_qty.
      end.

      {gprun.i ""rwroru1a.p""
         "(site,csset,routing,bom_code,ord_qty,eff_date,inc_yield)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if update-alts then do:
         for each ptr_det no-lock where ptr_part = pt_part
               and ptr_site = site:
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               routing = ptr_routing
               bom_code = ptr_bom_code.
            if routing = "" then routing = ptr_part.
            if bom_code = "" then bom_code = ptr_part.
            {gprun.i ""rwroru1a.p""
               "(site,csset,routing,bom_code,ord_qty,
            eff_date,inc_yield)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*for each pt_mstr*/
end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*repeat*/
